package tree;

public class OrderPrint {
    /**
     * 前序遍历
     * 公式 preOrderPrint(a) = print(a) + preOrderPrint(a.left) + preOrder(a.right)
     * 结束标志 a == null
     * @param pTreeNode
     */
    public void preOrderPrint(LinkedNode pTreeNode) {
        if (pTreeNode == null) {
            return;
        }

        System.out.println(pTreeNode.getObjData());
        preOrderPrint(pTreeNode.getLeftNode());
        preOrderPrint(pTreeNode.getRightNode());
    }

    /**
     * 中序遍历
     * 公式 preOrderPrint(a) = preOrderPrint(a.left) + print(a) + preOrder(a.right)
     * 结束标志 a == null
     * @param pTreeNode
     */
    public void inorderPrint(LinkedNode pTreeNode) {
        if (pTreeNode == null) {
            return;
        }

        inorderPrint(pTreeNode.getLeftNode());
        System.out.println(pTreeNode.getObjData());
        inorderPrint(pTreeNode.getRightNode());
    }

    /**
     * 后序遍历
     * 公式 preOrderPrint(a) = preOrderPrint(a.left) + preOrder(a.right) + print(a)
     * 结束标志 a == null
     * @param pTreeNode
     */
    public void afterOrderPrint(LinkedNode pTreeNode) {
        if (pTreeNode == null) {
            return;
        }

        inorderPrint(pTreeNode.getLeftNode());
        inorderPrint(pTreeNode.getRightNode());
        System.out.println(pTreeNode.getObjData());
    }
}
